<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>html-本地存储</title>
</head>
<body>
<div>
    <div>用户名：<input id="username"/></div>
    <div>密码：<input id="password"/></div>
    <div><button id="btnLogin">登录</button></div>

</div>
</body>
<script>

    document.getElementById('btnLogin').onclick = function () {

        /*1. 基本使用 */

       /* var username = document.getElementById('username').value;
      //  sessionStorage.setItem("username",username);

        localStorage.setItem("username",username);
        localStorage.clear();

        location.href = "index.html"*/

        var username = document.getElementById('username').value;
        var password = document.getElementById('password').value;

        /*localStorage.setItem("username",username);
        localStorage.setItem("passowrd",password);*/

        var user = {
            username:username,
            password:password
        }

        user = JSON.stringify(user);

        localStorage.setItem("user",user);

        location.href = "index.html";
    }


</script>
</html>